package cn.s1995.sloth.app.controller;

import java.util.List;

import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import cn.hutool.core.util.ObjectUtil;
import cn.s1995.sloth.bizs.entity.ProdCategory;
import cn.s1995.sloth.bizs.service.ProdCategoryService;
import cn.s1995.sloth.common.core.util.R;
import cn.s1995.sloth.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/m/prodCategory")
@Tag(description = "ProdCategory", name = "APP-产品分类模块")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ApiProdCategoryController {

	private final ProdCategoryService prodCategoryService;

	/**
	 * 获取分类列表
	 * @return
	 */
	@Inner(false)
    @Operation(summary = "获取产品分类", description = "获取产品分类")
    @GetMapping("/list")
    public R<List<ProdCategory>> getList(@ParameterObject ProdCategory req) {
        LambdaQueryWrapper<ProdCategory> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ProdCategory::getIsShow, true)
        	   .eq(ObjectUtil.isNotNull(req.getPid()), ProdCategory::getPid, req.getPid())
        	   .eq(ObjectUtil.isNotNull(req.getShopId()), ProdCategory::getShopId, req.getShopId())
        	   .eq(ObjectUtil.isNotNull(req.getLevel()), ProdCategory::getLevel, req.getLevel())
        	   .orderByAsc(ProdCategory::getSort);
        return R.ok(prodCategoryService.list(wrapper));
    }
}
